package Compilador;
import java.util.LinkedList;
import java_cup.runtime.*;
%%
%cupsym simbolos
%class lexico
%standalone
%8bit
%cup
%unicode
%public
%line
%column
%char
%ignorecase
%state ESTRING
%state COMENTARIO1
%state COMENTARIO2
%eofval{

	return new Symbol(simbolos.EOF,yyline,yycolumn);
%eofval}
%{/*Crear un nuevo objeto java_cup.runtime.Symbol con información sobre el token actual sin valor*/

  private Symbol symbol(int type){
    return new Symbol(type,yyline,yycolumn);
  }
  LinkedList<NodoError> listaErrores;
  public void setListaErrores(LinkedList<NodoError> principal){
    listaErrores=principal;
  }
  LinkedList<String> ListaDeTokenInterna;
  public void setListaToken(LinkedList<String> listatoken){
    ListaDeTokenInterna=listatoken;
  }
 /* Crear un nuevo objeto java_cup.runtime.Symbol con información sobre el token actual con valor*/
  private Symbol symbol(int type,Object value){
    return new Symbol(type,yyline,yycolumn,value);
  }

  String string = "";
  public String HTML="<html><body>";

 public int cinicio=0;
 public int cfin=0;
 public int cprints=0;
 public int cvariables=0;
  public int cgraficar=0;
  public int coperaciones=0;
  public int centeros=0;
  public int cflotantes=0;
  public int ccadenas=0;
  public int ccaracteres=0;
  public int coperandos=0;
  public int csimbolos=0;
  public int ccomentario=0;
<<<<<<< .mine

%}
=======
  public int abrirParentesis=0;
  public int cerrarParentesis=0;
  public int igualigual=0;
  public int puntoycoma=0;
  public int cPoma=0;
  public int dosPuntos=0;
  public int tpor=0;
  public int masmas=0;
  public int menosmenos=0;
  public int divisiondiv=0;
  
%} 
>>>>>>> .r31
/*-- MACRO DECLARACIONES --*/
id		= [a-zA-Z]([a-zA-Z]|[0-9]|"_")*
num_int		= ("-")?([0-9]+)
num_float		= ("-")?([0-9]+)(".")([0-9]+)
line_terminator	= \r|\n|\r\n
white_space    	= {line_terminator} | [ \t\f]
salto =  \n
estring		= [\"]
comilla		= ([\\])([\"])
cualquiera	= .
Chart          =[\'].[\']
%%
/*-------- Sección de reglas lexicas ------ */
<YYINITIAL>{

"<inicio>"			{cinicio++;HTML+="<font color=\"#00FF00\"> < inicio ></font>"; return symbol(simbolos.tinicio);			}
"<fin>"			{ cfin++;HTML+="<font color=\"#00FF00\"> < fin > </font>"; return symbol(simbolos.tfin);		}
"Print"			{ cprints++; HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tprint);			}
"var"			{cvariables++;HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tvar);			}
"Integer"			{HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tInteger, yytext());			}
"Float"			{HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tfloat, yytext());			}
"String"			{HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tString, yytext());			}
"Char"			{HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tchar, yytext());			}
"Operacion" 	{coperaciones++;HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.toperacion);		}
"Graficar" 		{cgraficar++; HTML+="<font color=\"#0000FF\">"+yytext()+"</font>"; return symbol(simbolos.tGraficar);		}
{id} 			{HTML+="<font color=\"#FF00FF\">"+yytext()+"</font>"; return symbol(simbolos.tid, yytext());		}
{num_int}		{centeros++;HTML+="<font color=\"#FF9900\">"+yytext()+"</font>"; return symbol(simbolos.num_int, yytext());	}
{num_float}		{cflotantes++;HTML+="<font color=\"#FFFF00\">"+yytext()+"</font>"; return symbol(simbolos.num_float, yytext());	}

"("			    {abrirParentesis++;HTML+=yytext();  return symbol(simbolos.parentesis_i);		}
")"   			{cerrarParentesis++; HTML+=yytext(); return symbol(simbolos.parentesis_d);		}
"=" 			{igualigual++; HTML+=yytext();return symbol(simbolos.tigual);		}
";" 			{puntoycoma++;HTML+=yytext(); return symbol(simbolos.punto_coma);		}
"," 			{cPoma++; HTML+=yytext();return symbol(simbolos.coma);		}
":" 			{dosPuntos++; HTML+=yytext(); return symbol(simbolos.dos_puntos);		}
"*"			    {tpor++; HTML+="<font color=\"#AC12CB\">"+yytext()+"</font>";return symbol(simbolos.por);			}
"+"			    {masmas++;HTML+="<font color=\"#AC12CB\">"+yytext()+"</font>"; return symbol(simbolos.plus);			}
"-"			{menosmenos++;HTML+="<font color=\"#AC12CB\">"+yytext()+"</font>"; return symbol(simbolos.menos);			}
{estring} 		{ccadenas++; yybegin(ESTRING); string = "";		}
{salto}  {HTML+="<br>";}
{white_space}		{ 			HTML+=yytext();			}
"//"  			{ ccomentario++;HTML+=yytext();yybegin(COMENTARIO1);				}
"/*" 			{ ccomentario++; HTML+=yytext();yybegin(COMENTARIO2);				}
"/"			{divisiondiv++;HTML+="<font color=\"#AC12CB\">"+yytext()+"</font>"; return symbol(simbolos.tdiv);			}
{Chart}                 {ccaracteres++; HTML+=yytext(); return symbol(simbolos.tvalchar, yytext());			}
{cualquiera}		{ 	HTML+=yytext();

NodoError nuevo=new NodoError();
nuevo.columna=String.valueOf(yyline);
nuevo.linea=String.valueOf(yycolumn);
nuevo.Descripcion="Error lexico ";
nuevo.palabra=yytext();
this.listaErrores.add(nuevo);

	}

}

<ESTRING>{
{salto}  {HTML+="<br>";}
{estring} 		{ 	yybegin(YYINITIAL);
				HTML+="<font color=\"#8D4705\">"+"\""+string+"\""+"</font>"; return symbol(simbolos.estring,"\""+string+"\""); }
[ \r\t\f]		{HTML+=yytext(); string += yytext();			}
{comilla}		{ string += yytext();			}
{cualquiera}		{ string += yytext();			}

}

<COMENTARIO1>{

{cualquiera}		{ HTML+="<font color=\"#C0C0C0\">"+yytext()+"</font>";					}
{salto}  {HTML+="<br>";string += yytext();	yybegin(YYINITIAL);	}
{line_terminator}	{string += yytext();	yybegin(YYINITIAL);		}
}

<COMENTARIO2>{
{cualquiera}		{ HTML+="<font color=\"#C0C0C0\">"+yytext()+"</font>";					}
"*/" 			{HTML+=yytext(); string += yytext();	yybegin(YYINITIAL);		}
}


